package com.bing.my.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bing.my.entity.Goose;
import com.bing.my.entity.Member;
import com.bing.my.entity.Recharge;
import com.bing.my.mapper.MemberMapper;
import com.bing.my.service.MemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 商品数据 服务实现类
 * </p>
 *
 * @author bing
 * @since 2021-10-12
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {

    @Resource
    private MemberMapper memberMapper;

    @Override
    public int insert(Member member) {
        return memberMapper.insert(member);
    }

    @Override
    public int deleteById(String id) {
        return memberMapper.deleteById(id);
    }

    @Override
    public int update(Member member) {
        return memberMapper.updateById(member);
    }

    @Override
    public Page<Member> selectPage(String search, String select, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<Member> like = null;
        if("phoneNumber".equals(select)){
            // 根据手机号查询
            like = Wrappers.<Member>lambdaQuery().eq(Member::getPhoneNumber, search)
                    // 根据创建时间倒序
                    .orderByDesc(Member::getGmtCreate);
        }else {
            //根据会员名称查询
            like = Wrappers.<Member>lambdaQuery().like(Member::getMemberName, search)
                    // 根据创建时间倒序
                    .orderByDesc(Member::getGmtCreate);
        }
        Page<Member> memberPage = memberMapper.selectPage(new Page<>(pageNum, pageSize), like);

        return memberPage;
    }

    @Override
    public Member selectById(String id) {
        return memberMapper.selectById(id);

    }
}
